#ifndef _STACK_CPP_
#define _STACK_CPP_

#include "stack.h"

template <class T>
stack<T>::stack()
{
	m_top = NULL;
}

template <class T>
stack<T>::~stack()
{
	makeEmpty();
}

template <class T>
bool stack<T>::isEmpty()
{
	return (m_top == NULL);
}

template <class T>
void stack<T>::makeEmpty()
{
	ItemType<T>* temp;
	while (m_top != NULL)
	{
		temp = m_top;
		m_top->setNext(m_top->getNext());
		delete temp;
	}
}

template <class T>
void stack<T>::push (ItemType<T> item)
{
	m_top = new ItemType<T>(item.getData(), m_top);
}

template <class T>
ItemType<T> stack<T>::pop()
{
	if (isEmpty())
		throw "The stack is empty!!!";

	ItemType<T>* temp = m_top;
	m_top = m_top->getNext();
	temp->setNext(NULL);
	return *temp;
}

#endif


